package com.g9.blog.repository;

import com.g9.blog.entity.Article;
import com.g9.blog.entity.ArticleLike;
import com.g9.blog.entity.Users;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Auther: Graycat
 * @Date: 2020/9/11 15:56
 * Create by lwj.
 */
public interface LikeRepository extends JpaRepository<ArticleLike,Integer> {

    //判断是否点过赞
    public List<ArticleLike> findAllByArticleIdAndUserId( int articleId,int userId );

    @Query(" select t from Article t where t.id in " +
            "( select al.articleId from ArticleLike al where al.userId = ?1 )" )
    public List<Article> findAllArticleByUserId( int userId );


    @Query(" select user from Users user where user.id in " +
            "( select al.userId from ArticleLike al where al.articleId = ?1 )" )
    public List<Users> findAllUserByArticleId(int articleId );

}
